<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>行政许可审批查询</title>

<%@ include file="/wf/public/meta_wf.jsp"%>
 
<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
<script type='text/javascript' src="${ctx}/dwr/util.js"></script>
<script src="${ctx}/wf/client/common/js/WfOpinionGrid.js" type="text/javascript"></script>
<script src="${ctx}/wf/client/common/js/WfOpinionPanel.js" type="text/javascript"></script>
<script src="${ctx}/wf/client/common/js/WfSendSuccessWin.js" type="text/javascript"></script>
<script src="${ctx}/wf/client/common/js/WfSendWin.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/shljcz/js/czStateGrid.js" type="text/javascript"></script>
<script src="${ctx}/wf/client/common/js/WfSendWin.js" type="text/javascript"></script>
<script src="${ctx}/resources/components/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	
<script type="text/javascript">

Ext.onReady(function(){
	Ext.QuickTips.init();
	var PersonRecord=Ext.data.Record.create([
	 	{name:'id',type:'string'}
	]);
	var data = [['boy'],['girl']];
	
	var store = new Ext.data.Store({
	    proxy: new Ext.data.MemoryProxy(data),
	    reader: new Ext.data.ArrayReader({}, PersonRecord)
	});
	store.load();
	
	var ndate=getNowDate(0);
	var ydate=getNowDate(-3);
	//查询
	var searchForm = new Ext.FormPanel({
		region: 'north',
		title: '行政许可审批查询',
		labelAlign: 'right',
		height: 130,
		frame: true,
		plain: true,
		collapsible: true,
		border: true,
		margins: '1 1 2 1',
		items: [{
			layout: 'column',
			items:[{
				columnWidth: .3,
				layout: 'form',
				items: [{
					xtype: 'textfield',
					fieldLabel: '法人名称',
					name: 'qyname',
					emptyText:'请输入法人名称',
					width: 180
				}]
			},{
				columnWidth: .3,
				layout: 'form',
				items: [{
					id:'startdate',
					xtype: 'datefield',
					fieldLabel: '开始时间',
					name: 'startdate',
					format:'Y-m-d',
					value:ydate,
					editable:false,
					width: 120
				}]
			},{
				columnWidth: .3,
				layout: 'form',
				items: [{
					xtype: 'datefield',
					fieldLabel: '结束时间',
					value:ndate,
					name: 'enddate',
					format:'Y-m-d',
					editable:false,
					width: 120
				}]
			}]
		},{
				columnWidth: .3,
				layout: 'form',
				items: [{
	              xtype:'textfield',
	              fieldLabel: '审批项目',
	              name: 'CBYW',
	              id:'spywId',
	         	  width: 280,
	              xtype:'combo',
		          store: new Ext.data.Store({
			          proxy: new Ext.data.MemoryProxy([['城市生活垃圾经营性处置','城市生活垃圾经营性处置'],
											          	['水域生活垃圾经营性清扫、收集、运输','水域生活垃圾经营性清扫、收集、运输'],
											          	['陆域生活垃圾经营性清扫、收集、运输','陆域生活垃圾经营性清扫、收集、运输']
											         ]),
			          reader: new Ext.data.ArrayReader({}, [
			              {name: 'value',mapping: 0, type: 'string'},
			              {name: 'text',mapping: 0}
			          ]),
			          autoLoad:true
			      }) ,
	       
		          displayField:'text',
		          valueField:'value',
		          typeAhead: true,
		          value:'陆域生活垃圾经营性清扫、收集、运输',
		          triggerAction: 'all',
		          emptyText:'请选择审批业务'
		          }]
			},{
			layout: 'column',
			items:[{
				columnWidth: .3,
				layout: 'hbox',
				defaults:{margins:'0 5 0 40'},
				buttonAlign:"right",
				items:[{
					xtype: 'button',
					text: '&nbsp;查询',
					width: 80,
					iconCls: 'icon-find',
					handler: function(){
						var spyw=Ext.get('spywId').dom.value;
						if(spyw.indexOf("水域")>=0){
							this.summaryGrid.colModel.setColumnHeader(8,"核准经营车辆");
							this.summaryGrid.store.load();
						  
						}else if(spyw.indexOf("陆域")>=0){
							this.summaryGrid.colModel.setColumnHeader(8,"核准经营车辆");
							this.summaryGrid.store.load();
						
						}else{
							this.summaryGrid.colModel.setColumnHeader(8,"核准经营规模(吨/年)");
							this.summaryGrid.store.load();
						}
						
					},
					scope: this
				},{
					xtype: 'button',
					text: '清空',
					width: 80,
					handler: function(){
						this.searchForm.form.reset();
						//window.location.href="csshlj-cz!toListStateDb.action";
						 this.summaryGrid.store.load();
					},
					scope: this
				}]
			}]
		}]
	});
	this.searchForm = searchForm;
	var startdate=searchForm.form.findField('startdate').getValue();
	var sqyw=searchForm.form.findField('CBYW').getValue();
 	var url='${ctx}/csshlj-cz!getDdDatas.action';
	var summaryGrid = new Ext.ux.grid.czStateGrid({
		id: 'statesummary',
		region: 'center',
		margins: '0 1 1 1',
		url: url,
		keyField: 'id',
		defaultSortField: 'create',
		structure: [{
			name: 'id',
			hidden: true
		},{
			name: 'validstarttime',
			hidden: true
		},{
			name: 'validendtime',
			hidden: true
		},{
				name:'sqdw',
				header:'法人名称',
				width:180
			},{  
			name: 'address',  
			header: '办公住所',
			sortable: true,
			width: 100
		 },{
			name: 'ssAddr',  
			id:'ssAddr',
			header: '设施地址',
			width: 100
		},{
			name: 'cbyw',  
			id:'cbyw',
			header: '核准经营范围',
			width: 100
		},{
			name: 'jyscale',  
			header: '核准经营车辆',
			width: 140
		},{
			name: 'frdb',  
			header: '法定代表人',
			width: 80
		},{
			name: 'frdb',  
			header: '联系人',
			width: 80
		},{
			name: 'companyphone',  
			header: '联系电话',
			width: 80

		},{
			name: 'validdate',  
			header: '许可证有效期',
			width: 150
		}]
		
	});
	
	this.summaryGrid = summaryGrid;

	var viewport = new Ext.Viewport({
		layout: 'border',
		items: [searchForm, summaryGrid]
	});

	var store = summaryGrid.store;
	store.on('beforeload', function(){
		store.baseParams = {
			groupBy: store.groupField ? store.groupField : null,
			qyname: searchForm.form.findField('qyname').getValue(),//法人名称
			startdate: searchForm.form.findField('startdate').getValue(),
			enddate: searchForm.form.findField('enddate').getValue(),
			spyw:searchForm.form.findField('CBYW').getValue()
		};
	}, this);
	
	refresh = function () {
      this.summaryGrid.store.load();
	}
	
});

//导出
function exportData(){
	 var spyw=Ext.get('spywId').dom.value;
	 var sqdw=searchForm.form.findField('qyname').getValue();//法人名称
	 if(spyw=="" || spyw.indexOf("审批业务")>=0){
		alert("请选择审批业务");
		return;
	}
     var action="${ctx}/csshlj-cz!exportDbDatas.action"+getParams();
      var wait = new Ext.LoadMask(Ext.getBody(), {msg:"请稍后..."}); 
      wait.show();
	 Ext.Ajax.request({
	     url:action,
	     params:{spyw:spyw,sqdw:sqdw},
	    method:'POST',
    success:function(response){
    	var path=response.responseText;
    	var url="${ctx}/"+path;
    	wait.hide();
    	window.open(path);
    },
   failure: function() {
   		wait.hide();
       Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
    }
	
	//window.location.href=action;
});
}
//获取参数
function getParams(){
	var qyname=searchForm.form.findField('qyname').getValue();//法人名称
	var startdate=searchForm.form.findField('startdate').getValue();
	var  enddate=searchForm.form.findField('enddate').getValue();
	if(startdate!=""){//ext日期转换
		var sday=startdate.getDate();
		if(startdate.getDate()<10){
			sday="0"+sday
		}
		startdate=startdate.getFullYear()+"-"+(startdate.getMonth()+1)+"-"+sday;
	}
	if(enddate!=""){//ext日期转换
		var eday=enddate.getDate();
		if(enddate.getDate()<10){
			eday="0"+eday
		}
		enddate=enddate.getFullYear()+"-"+(enddate.getMonth()+1)+"-"+eday;
	}
	var param="?startdate="+startdate+"&enddate="+enddate+"&qyname="+qyname;
	return param;
}


//获取当前时间
function getNowDate(n){
	 var dateTime;
	  var myDate = new Date();
	  myDate.setDate(myDate.getDate()+n);   
	  var year = myDate.getFullYear()
	  var month = myDate.getMonth()+1;
	  var day = myDate.getDate();
	  if(month < 10)
	            month = "0"+month;
	  if(day < 10)
	            day = "0"+day;
	  var dateTime = year +"-"+month+"-"+ day ;
	return dateTime;
}

//修改页面

function editData(){
	 	var sel=  summaryGrid.getSelectionModel().getSelections();//获取所有更新过的记录   
		 var spyw=Ext.get('spywId').dom.value;
		 if(spyw=="" || spyw.indexOf("审批业务")>=0){
			alert("请选择审批业务");
			return;
		}
		var jyscale=""; 
		if(spyw.indexOf("处置")>=0){
			jyscale="核准经营规模(吨/年)";
		}else{
		   jyscale="核准经营车辆";
		}
		var win=new Ext.Window({
        title:'修改',
        width:600,
        autoHeight:true,    
        modal: true,
        labelAlign:'right',
        buttonAlign:'center',
        closeAction:'close',
        html:'<table width="700" border="0" cellspacing="2" cellpadding="2">'+
        '<tr><td colspan="2"><input type="hidden" name="id" id="id" value="'+sel[0].get('id')+'"></td>'+
        '<tr><td width:200 align=center width="20%" >法人名称:</td><td width="70%" align=left><input type="text" name="name" size="45"  readonly="true" id=" " value="'+sel[0].get('sqdw')+'"></td>'+
        '<tr><td width:200 align=center>办公住所:</td><td align=left><input type="text" name="address"  id="address" size="45" readonly="true" value="'+sel[0].get('address')+'"></td>'+
        '<tr><td width:200 align=center>设施地址:</td><td align=left><input type="text" name="ssAddr" id="ssAddr" size="45"  readonly="true" value="'+sel[0].get('ssAddr')+'"></td>'+
		 '<tr><td width:200 align=center>核准经营范围:</td align=left><td><input type="text" name="cbyw" id="cbyw" size="45" readonly="true" value="'+sel[0].get('cbyw')+'"></td>'+
		 '<tr><td width:200 align=center>'+jyscale+'</td align=left><td><input type="text" name="jyscale" id="jyscale" readonly="true" size="45" value="'+sel[0].get('jyscale')+'"></td>'+
		 '<tr><td width:200 align=center>法定代表人:</td><td align=left><input type="text" name="frdb" id="frdb" size="45" readonly="true" value="'+sel[0].get('frdb')+'"></td>'+
		 '<tr><td width:200 align=center>联系人:</td><td align=left><input type="text" name="frdb" id="frdb" size="45" readonly="true" value="'+sel[0].get('frdb')+'"></td>'+
		 '<tr><td width:200 align=center>联系电话:</td><td align=left><input type="text" name="companyphone" id="companyphone"  readonly="true" size="45" value="'+sel[0].get('companyphone')+'"></td>'+
		 '<tr><td width:200 align=center>许可证开始时间:</td align=left><td><input type="text" name="validstarttime" onclick="WdatePicker();" id="validstarttime"  class="" readonly="true" size="45" value="'+sel[0].get('validstarttime')+'"></td>'+
		'<tr><td width:200 align=center>许可证结束时间:</td><td align=left><input type="text" name="validendtime" id="validendtime"  onclick="WdatePicker();" class="" size="45" readonly="true" value="'+sel[0].get('validendtime')+'"></td>'+
        '</table>',
        buttons:[{text:'保 存',handler:function(){
	       	var id =Ext.get('id').dom.value;
	       	var ssAddr=Ext.get('ssAddr').dom.value;
	       	var validstarttime=Ext.get("validstarttime").dom.value;
	       	var validendtime=Ext.get("validendtime").dom.value;
	       	var type=spyw;
			var url="${ctx}/csshlj-cz!doUpdateDate.action";
			var obj ={
				  id:id,
				  type:type,
				  starttime:validstarttime,
				   endtime:validendtime
			};
		     Ext.Ajax.request({
			     url:url,
			     params:obj,
			     method:'POST',
			     success:function(response){
			         var result=response.responseText;
			         if(result=="success"){
			              Ext.Msg.alert("提示","保存成功");
			              win.close();
			              //summaryGrid.store.load();
			              return;
			         }
			       
			    }, failure: function() {
			        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
			     } 
		 	 });
        }
        },{text:'取 消',handler:function(){
            win.close();
        }}]
    }).show();	
}

</script>
</head>

<body>
</body>
</html>